package chances.wechat.api;

import java.io.Serializable;
import java.util.Date;

public class TokenSet implements Serializable {

	private static final long serialVersionUID = 2592781527717573580L;
	String appId;
	private String secret;
	private String appCode;
	String accessToken = "";
	String jsApiTicket = "";
	long jsTokenStartTime;
	long accessTokenStartTime;
	private Date createTime;
	private Date updateTime;

	public String getAccessToken() {
		return accessToken;
	}

	public void setAccessToken(String accessToken) {
		this.accessToken = accessToken;
	}

	public String getJsApiTicket() {
		return jsApiTicket;
	}

	public void setJsApiTicket(String jsApiTicket) {
		this.jsApiTicket = jsApiTicket;
	}

	public long getJsTokenStartTime() {
		return jsTokenStartTime;
	}

	public void setJsTokenStartTime(long jsTokenStartTime) {
		this.jsTokenStartTime = jsTokenStartTime;
	}

	public long getAccessTokenStartTime() {
		return accessTokenStartTime;
	}

	public void setAccessTokenStartTime(long accessTokenStartTime) {
		this.accessTokenStartTime = accessTokenStartTime;
	}

	public String getAppId() {
		return appId;
	}

	public void setAppId(String appId) {
		this.appId = appId;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public String getSecret() {
		return secret;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}

	public String getAppCode() {
		return appCode;
	}

	public void setAppCode(String appCode) {
		this.appCode = appCode;
	}
	
	public boolean isAccessTokenRefresh(int timeout) {
		if(timeout == 0) {
			return isAccessTokenRefresh();
		}
		Date updateTime = this.getUpdateTime();
		return (System.currentTimeMillis() - updateTime.getTime() > 
			(timeout * 1000));
	}
	
	public boolean isJsTokenRefresh(int timeout) {
		if(timeout == 0) {
			return isJsTokenRefresh();
		}
		Date updateTime = this.getUpdateTime();
		return (System.currentTimeMillis() - updateTime.getTime() > 
			(timeout * 1000));
	}
	
	public boolean isAccessTokenRefresh() {
		Date updateTime = this.getUpdateTime();
		return (System.currentTimeMillis() - updateTime.getTime() > 
			(this.getAccessTokenStartTime() * 1000));
	}
	
	public boolean isJsTokenRefresh() {
		Date updateTime = this.getUpdateTime();
		return (System.currentTimeMillis() - updateTime.getTime() > 
			(this.getJsTokenStartTime() * 1000));
	}

}
